<?php
namespace app\Index\controller;
use think\Controller;
use think\Db;
/**
* 
*/
class Book extends Controller
{
	//连库
	public function book()
	{
		$data = db::table('newbook')->select();
		// var_dump($data);
		$this->assign('list',$data);
		return $this -> fetch('book/book');
	}
	//检索
	public function fuzzy_query(){
		$type=input('type');
		$result=input('result');	
        if($type == 'Name'){
	    	$sql="SELECT * FROM newbook WHERE Name LIKE '%".$result."%'";
	       $data= Db::query($sql);
	      	// var_dump($data);
	       $this->assign('list',$data);
	       return $this->fetch('book/book');
	    }
	    if($type == 'Publisher'){
	    	$sql="SELECT * FROM newbook WHERE Publisher LIKE '%".$result."%'";
	       $data= Db::query($sql);
	      	// var_dump($data);
	       $this->assign('list',$data);
	       return $this->fetch('book/book');
	    }
	    if($type == 'Type'){
	    	$sql="SELECT * FROM newbook WHERE Type LIKE '%".$result."%'";
	       $data= Db::query($sql);
	      	// var_dump($data);
	       $this->assign('list',$data);
	       return $this->fetch('book/book');
	    }
	    if($type == 'Writer'){
	    	$sql="SELECT * FROM newbook WHERE Writer LIKE '%".$result."%'";
	       $data= Db::query($sql);
	      	// var_dump($data);
	       $this->assign('list',$data);
	       return $this->fetch('book/book');
	    }
	    if($type == 'Label'){
	    	$sql="SELECT * FROM newbook WHERE Label LIKE '%".$result."%'";
	       $data= Db::query($sql);
	      	// var_dump($data);
	       $this->assign('list',$data);
	       return $this->fetch('book/book');
	    }
	    if($type == 'Id'){
	    	$sql="SELECT * FROM newbook WHERE Id LIKE '%".$result."%'";
	       $data= Db::query($sql);
	      	// var_dump($data);
	       $this->assign('list',$data);
	       return $this->fetch('book/book');
	    }
	}
}
